/*
 * @Author: junxu821 xu.jun.work@qq.com
 * @Date: 2025-09-12 14:01:11
 * @LastEditors: junxu821 xu.jun.work@qq.com
 * @LastEditTime: 2025-09-12 14:25:53
 * @FilePath: \gulp-style\gulpfile.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

// const sass = require('gulp-sass')(require('sass'));
// const cleanCSS = require('gulp-clean-css'); // 引入CSS压缩插件
// const autoprefixer = require('gulp-autoprefixer'); // 引入自动添加浏览器前缀插件
// const sourcemaps = require('gulp-sourcemaps'); // 引入sourcemap插件
import gulp from 'gulp'
import cleanCSS from 'gulp-clean-css';
import autoprefixer from 'gulp-autoprefixer';
import sourcemaps from 'gulp-sourcemaps';
import gulpSass from 'gulp-sass';
import * as dartSass from 'sass';

const sass = gulpSass(dartSass);
function compileSassProduction() {
  return gulp.src('src/styles/**/*.scss')
//  return gulp.src('src/styles/index.scss')
    .pipe(sourcemaps.init()) // 初始化sourcemap
    .pipe(sass().on('error', sass.logError))
    .pipe(autoprefixer({ // 自动添加浏览器厂商前缀
      cascade: false
    }))
    .pipe(cleanCSS( { compatibility: 'ie8' } )) // 压缩CSS代码
    .pipe(sourcemaps.write('.')) // 将sourcemap写入单独的文件（例如：styles.css.map）
    .pipe(gulp.dest('dist/css'));
}

export const build = compileSassProduction;